#ifndef MQTT_IPC_H
#define MQTT_IPC_H

#include "qmqtt.h"

#include <QTimer>

//const QHostAddress INNER_HOST = QHostAddress::LocalHost;
const QHostAddress INNER_HOST = QHostAddress("192.168.8.195");
const quint16 INNER_PORT = 1883;
const QString INNER_TOPIC = "inner";


class MQTT_IPC : public QMQTT::Client
{
Q_OBJECT

public:
    explicit MQTT_IPC(const QHostAddress &host = INNER_HOST,
                      quint16 port = INNER_PORT,
                      const QString &topic = INNER_TOPIC,
                      QObject *parent = nullptr);

    ~MQTT_IPC() override = default;

    void mqttConnect();

    void mqttDisconnect();

    void sendMsg(const QString &topic, const QString &msg);

public slots:

    void onConnected();

    void onDisconnected();

    void onSubscribed(const QString &topic);

    void onReceived(const QMQTT::Message &message);

signals:

    void recvMsg(QByteArray payload);

private:
    QString mMsg;
    QString mSubTopic;
    QString mPubTopic;
};

#endif // MQTT_IPC_H
